package com.yuanian.timingwheel.model.task.executestragy;

import com.yuanian.timingwheel.model.task.base.BaseTask;

/**
 * 重试策略
 */
public class RetryExecutionStrategy implements ExecutionStrategy {

    protected BaseTask task;

    protected int retryCount;

    protected int curRetryCount;

    public RetryExecutionStrategy(BaseTask task) {
        this.task = task;
        this.retryCount = 10;
        this.curRetryCount = 0;
    }

    @Override
    public void onSuccess() {
        this.task.getTaskInfo().postExecute(task);
    }

    @Override
    public boolean onFailure() {
        if (curRetryCount++ < retryCount) {
            return task.execute();
        }
        return false;
    }
}
